#!/usr/bin/env python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='transaction-queue')
channel.exchange_declare(exchange="transaction-exchange",exchange_type="direct")
channel.queue_bind(queue="transaction-queue",exchange="transaction-exchange",routing_key="hola")

try:
   channel.tx_select()
   channel.basic_publish(exchange='transaction-exchange',routing_key='hola',body='Hello World!')
   #result = 1/0
   channel.tx_commit()
except Exception as e:
   print e
   channel.tx_rollback()

print(" [x] Sent 'Hello World!'")
connection.close()
